//
//  TabBarController.m
//  YXLTabbar
//
//  Created by 李庆春 on 15/5/18.
//  Copyright (c) 2015年 YXL. All rights reserved.
//
//动态获取设备高度
#define IPHONE_HEIGHT [UIScreen mainScreen].bounds.size.height
//动态获取设备宽度
#define IPHONE_WIDTH [UIScreen mainScreen].bounds.size.width
#import "TabBarController.h"

@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createController];
    [self creatUI];
}

- (void)creatUI
{
    TabbarView *tabbarView = [[TabbarView alloc]initWithFrame:CGRectMake(0, IPHONE_HEIGHT-49.0f, IPHONE_WIDTH, 49.0f)];
    
    
    [self.view addSubview:tabbarView];
    
    tabbarView.sendBlock = ^(UIButton *sender)
    {
//        for (int i = 1001; i < 1004; i ++) {
//            UIButton * btn = (UIButton *)[self.view viewWithTag:i];
//            btn.selected = NO;
//        }
//        sender.selected = YES;
        [self btnClick:sender];
    };
    
    
    
}

- (void)createController
{
//    [self.navigationItem setBarTintColor:[UIColor colorWithRed:93/255.0 green:152/255.0 blue:253/255.0 alpha:1.0]];
//    [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    
    MainViewController * mainViewController = [[MainViewController alloc]init];
    UINavigationController * naviController1 = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    mainViewController.navigationItem.title = @"首页";
    
    
    ChatListViewController * chatListViewController = [[ChatListViewController alloc]init];
    UINavigationController * naviController2 = [[UINavigationController alloc] initWithRootViewController:chatListViewController];
    chatListViewController.navigationItem.title = @"交流群";
    
    MineViewController * mineViewController = [[MineViewController alloc]init];
    UINavigationController * naviController3 = [[UINavigationController alloc] initWithRootViewController:mineViewController];
    mineViewController.navigationItem.title = @"我的";
    
    self.viewControllers = @[naviController1,naviController2,naviController3];
}


#pragma mark - ================= 各点击事件的判断触发 ===================

- (void)btnClick:(UIButton *)sender
{
    //NSLog(@"%ld",(long)sender.tag);
    switch (sender.tag) {
        case 1001:
        {
            self.selectedIndex = 0;
        }
            break;
        case 1002:
        {
            self.selectedIndex = 1;
        }
            break;
        case 1003:
        {
            self.selectedIndex = 2;
        }
            break;
            
        default:
            break;
    }
    
}

-(void)setTabBarHiden {
    
    self.tabBar.alpha = .0;
    
    self.tabBar.frame = CGRectMake(0, 0, 0, 0);
    
    self.tabBar.hidden = YES;
    
    [self.tabBar removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
